<?php

class UsuarioController extends Websis_Controller_Action
{
    public function formularioAction()
    {
        $this->view->form = $this->getForm();
    }

    public function getForm()
    {
        $form = new Application_Form_Usuario();
        $form->setAction($this->view->baseUrl('usuario/gravar'));
        return $form;
    }

    public function gravarAction()
    {
        $form = $this->getForm();

        if(!$form->isValid($this->_getAllParams())){
            $this->view->form = $form;
            return $this->render('formulario');
        }

        // Continua a gravação no banco
    }

    public function validateAction()
    {
        $validate = new Zend_Validate_Alnum();
        $validate->isValid('dasjdh s%%%');

        $validate = new Zend_Validate_Alpha();
        $validate->isValid('dasjdh s%%% 123871263876');

        $validate = new Zend_Validate_EmailAddress();
        $validate->isValid('orionteles@gmail.com');

        $validate = new Websis_Validate_ConfirmarSenha(array('senha'=>'123'));
        $validate->isValid('123456');

        ver($validate->getMessages());
        die;
    }

    public function filtroAction()
    {

        ver(Zend_Filter::filterStatic('Orion %%%%% Teles de Mesquita %%%', 'Alnum'));

        $filter = new Zend_Filter_Alnum();
        ver($filter->filter('Orion %%%%% Teles de Mesquita %%%'));

        $filter = new Zend_Filter_Word_UnderscoreToCamelCase();
        ver($filter->filter('orion_teles_de_mesquita'));

        $filter = new Zend_Filter_Word_CamelCaseToUnderscore();
        ver($filter->filter('OrionTelesDeMesquita'));

        Zend_Filter::filterStatic('teste', 'Alnum');
        echo Zend_Validate::is('dakjsdh %%%', 'Alnum');

        $filter = new Zend_Filter_Digits();
        ver($filter->filter('007.000.000-99'));

        ver(Zend_Filter::filterStatic('teste', 'StringPad', array(), 'Websis_Filter'));

        die;

    }

}